<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="./lib/index.css">
    <script src="./lib/vue.js"></script>
    <!-- <script src="./lib/vue.min.js"></script> -->
    <script src="./lib/index.js"></script>
    <script src="./lib/axios-0.18.0.js"></script>
    <script src="./http/http.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .login-container {
            display: flex;
            align-items: center;
            width: 100%;
            height: 100vh;
            background: url("./img/background.jpg");
            background-repeat: no-repeat;
            background-size: cover;
        }

        .login_form {
            margin: 0 auto;
            width: 70%;
            height: 35vh;
            background: url("./img/login_form.png");
            padding: 20px;
            border-radius: 10px;
            box-shadow:
                10px 10px 30px rgba(0, 0, 0, .5),
                -10px -10px 30px rgba(255, 255, 255, .5),
                inset 5px 5px 10px rgba(255, 255, 255, .5),
                inset -1px -1px 10px rgba(0, 0, 0, .5);
        }

        h1 {
            color: white;
            font-size: 40px;
        }

        h2 {
            color: white;
            font-size: 16px;
            margin: 20px 0;
        }

        .login_btn {
            width: 100%;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="login-container">

            <el-form class="login_form">
                <h1>Hello</h1>
                <h2>欢迎来到代跑跑快递配送系统</h2>
                <el-form-item prop="username">
                    <el-input v-model="username"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button :loading="loading" type="primary" class="login_btn" @click="login">登录</el-button>
                </el-form-item>
            </el-form>

        </div>
    </div>
</body>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                loading: false,
                username: ''
            }
        },
        methods: {
            async login() {
                this.loading = true
                if (!this.username) {
                    this.$message({
                        showClose: true,
                        center: true,
                        message: '请填写密钥',
                        type: 'error'
                    });
                    this.loading = false
                    return
                }
                const result = await axios({
                    method: 'GET',
                    url: '/user/helper/login',
                    params: {
                        key: this.username
                    }
                })
                if (result.code === 1) {
                    this.$message({
                        showClose: true,
                        center: true,
                        message: '登陆成功',
                        type: 'success'
                    });
                    localStorage.setItem('token', result.data.token)
                    setTimeout(() => {
                        location.href = './order.html'
                    }, 1000)
                }
            }
        }
    })
</script>

</html>